package main

import (
	"fmt"
	"struct_tag/cmd"
	"time"
)

func main() {
	//var user = json.UserInfo{UserName: "huangjinjin", Age: 30}
	//s, _ := json.ToJSONString(user)
	//fmt.Println("s == ", s)
	//
	//var tUser json.UserInfo
	//tUser, _ = json.GetObject(s)
	//fmt.Println(tUser.UserName, tUser.Age)
	//
	//fmt.Println("--------------------------")
	//person := xml.Person{Name: "huangjinjin", Age: 18, Address: "sz"}
	//xmlString, err := xml.ToXMLString(person)
	//if err != nil {
	//	return
	//}
	//fmt.Println(xmlString)
	//xmlObj, err := xml.GetObject(xmlString)
	//if err != nil {
	//	fmt.Println(err.Error())
	//	return
	//}
	//fmt.Println(xmlObj.Name, xmlObj.Address, xmlObj.Age)
	//
	//fmt.Println("--------------------------")
	//person2 := xml.Person{Name: "huangjinjin", Age: 18, Address: "sz"}
	//yamlStr, err := yaml.ToYamlString(person2)
	//if err != nil {
	//	return
	//}
	//fmt.Println("yamlStr===", yamlStr)
	//pObj, err := yaml.GetObject(yamlStr)
	//if err != nil {
	//	return
	//}
	//fmt.Printf("yamlStr===%#v\n", pObj)
	//
	//var str string
	//b := strings.TrimSpace(str) == ""
	//b2 := len(str) == 0
	//fmt.Println(b, b2)
	//
	//fmt.Println("----------------")
	//channelTest3()

	////定义一个通道
	//ch := make(chan int)
	//
	//go func() {
	//	//从一个通道中接收值。
	//	x := <-ch // 从ch中接收值并赋值给变量x
	//	fmt.Println("x = ", x)
	//}()
	////将一个值发送到通道中。
	//ch <- 10 // 把10发送到ch中
	//fmt.Println("main func is end")
	////<-ch // 从ch中接收值，忽略结果

	//standard.DoMD5()

	cmd.Execute()
}

func channelTest1() {
	ch := make(chan int)
	go func() {
		ch <- 996 //向ch添加元素
	}()
	a := <-ch
	fmt.Println(a)
	fmt.Println("程序结束！")
}

func channelTest2() {
	tc := make(chan string)
	ch := make(chan int)
	// 第一个协程
	go func() {
		tc <- "协程A，我在添加数据"
		ch <- 1
	}()
	// 第二个协程
	go func() {
		content := <-tc
		fmt.Printf("协程B，我在读取数据:%s\n", content)
		ch <- 2
	}()
	i1 := <-ch
	i2 := <-ch
	fmt.Println("程序结素！", i1, i2)
	close(tc)
	close(ch)
}

func goRoutineA(a <-chan int) {
	val := <-a
	fmt.Println("goRoutineA received the data", val)
}

func goRoutineB(b chan int) {
	val := <-b
	fmt.Println("goRoutineB received the data", val)
}

func channelTest3() {
	ch := make(chan int, 3)
	go goRoutineA(ch)
	go goRoutineB(ch)
	ch <- 3
	ch <- 4
	time.Sleep(time.Second * 1)
}
